package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Api(tags = "报警管理端")
public class AlertController extends BaseController{
    @Autowired
    private AlertService alertService;
    @PostMapping("/create")
    @ApiOperation(value = "申请入住")
    public ResponseResult<AlertRuleVo> addAlert(@RequestBody AlertRuleDto alertRuleDto) {
        alertService.addAlert(alertRuleDto);
        return ResponseResult.success();
    }
    @GetMapping("/get-page")
    @ApiOperation(value = "分页查询报警列表")
    public ResponseResult<PageResponse<AlertRuleVo>> pageQuery(Integer pageNum, Integer pageSize,String alertRuleName,
                                                                                    String functionName, String productKey) {
        PageResponse<AlertRuleVo> pageResponse = alertService.pageQuery(pageNum, pageSize,alertRuleName,functionName, productKey);
        return ResponseResult.success(pageResponse);
    }
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除报警")
    public ResponseResult deleteAlert(@PathVariable Long id) {
        alertService.deleteAlert(id);
        return ResponseResult.success();
    }

    @PutMapping("/update/{id}")
    @ApiOperation(value = "更新报警")
    public ResponseResult updateAlert(@RequestBody AlertRuleDto alertRuleDto) {
        alertService.updateAlert(alertRuleDto);
        return ResponseResult.success();
    }
}
